<?php include_once './application/views/sys_admin/common/header.php';  ?>

<script   language="javascript">
function changeRule(_this){
	var id = $(_this).attr("dataid");
	if(id>0){
		$( "#dialog" ).dialog({
			height:350,
			width:500,
			modal:true, //蒙层（弹出会影响页面大小）
			title:'编辑投资积分规则'
		});
		
		$("#id").val(id);
		
		$("#edit_vip_name").val($(_this).attr("vip_name"));
		$("#edit_minscore").val($(_this).attr("minscore"));
		$("#edit_maxscore").val($(_this).attr("maxscore"));
		$("#edit_investpercent").val($(_this).attr("investpercent"));
		$("#edit_pic").val($(_this).attr("pic"));
	}
}

function submitRule(){
	var id = $("#id").val();
	if(id > 0){
		$.ajax({
			type: "POST",
			url: "/sys_admin/user/uviplsave",
			data: "act=edit&id="+id+"&vip_name="+$("#edit_vip_name").val()+"&minscore="+$("#edit_minscore").val()+"&maxscore="+$("#edit_maxscore").val()+"&investpercent="+$("#edit_investpercent").val()+"&pic="+$("#edit_pic").val(),
			success: function(ret){
				$("#dialog" ).dialog();
				$("#msg").html(ret.msg);
				setTimeout(function(){
					$("#dialog" ).dialog("close");
				},3000);
				window.location.reload();
			},
			dataType: "json"
		});	
	}
}

function addRule(){
	$( "#adddialog" ).dialog({
		height:350,
		width:500,
		modal:true, //蒙层（弹出会影响页面大小）
		title:'添加投资积分规则'
	});
}

function addsubmitRule(){

	if($("#add_vip_name").val() == ""){
		$("#adddialog" ).dialog();
		$("#addmsg").html('请输入VIP等级名称');
		return false;
	}

	if($("#add_minscore").val() == ""){
		$("#adddialog" ).dialog();
		$("#addmsg").html('请输入投资积分下限');
		return false;
	}

	if($("#add_maxscore").val() == ""){
		$("#adddialog" ).dialog();
		$("#addmsg").html('请输入投资积分上限');
		return false;
	}
	if($("#add_investpercent").val() == ""){
		$("#adddialog" ).dialog();
		$("#addmsg").html('请输入购买配比');
		return false;
	}
	//TODO 修改
	if($("#add_pic").val() == ""){
		$("#adddialog" ).dialog();
		$("#addmsg").html('请正确填写 级别图片文件名');
		return false;
	}
	
		$.ajax({
			type: "POST",
			url: "/sys_admin/user/uviplsave",
			data: "act=add&vip_name="+$("#add_vip_name").val()+"&minscore="+$("#add_minscore").val()+"&maxscore="+$("#add_maxscore").val()+"&investpercent="+$("#add_investpercent").val()+"&pic="+$("#add_pic").val(),
			success: function(ret){
				$("#adddialog" ).dialog();
				$("#addmsg").html(ret.msg);
				setTimeout(function(){
					$("#adddialog" ).dialog("close");
				},3000);
				window.location.reload();
			},
			dataType: "json"
		});	
}

function removeRule(id){
	if(confirm('你确定要删除?'))
	{
		if(id > 0){
			$.ajax({
				type: "POST",
				url: "/sys_admin/user/uviplsave",
				data: "act=delete&id="+id,
				success: function(ret){
					window.location.reload();
				},
				dataType: "json"
			});	
		}	
	}	
}
</script>
<div id="dialog" title="系统提示" style="display:none;">
	<form  class="form-inline definewidth m20">
	<div id="msg" style="text-align:center;color:red"></div>
	<input type="hidden" name="id" id="id" />
	<table class="table table-bordered table-hover m10">
		 <tr>
	        <td class="tableleft">VIP等级名称</td>
	        <td><input type="text" name="vip_name" id="edit_vip_name" /></td>
	   	</tr>
	   	<tr>
	        <td class="tableleft"> 积分下限</td>
	        <td> <input type="text" name="minscore" id="edit_minscore" /> </td>
	   	</tr>
	   	<tr>
	        <td class="tableleft"> 积分上限</td>
	        <td><input type="text" name="maxscore" id="edit_maxscore" /> </td>
	   	</tr>
	   	<tr>
	        <td class="tableleft"> 购买配比(%)</td>
	        <td><input type="text" name="investpercent" id="edit_investpercent" /> </td>
	   	</tr>
	   	<tr>
	        <td class="tableleft">级别图片文件名 </td>
	        <td><input type="text" name="pic" id="edit_pic" /> </td>
	   	</tr>
	</table>
	<div style="text-align:center;">
		<button type="button" class="btn btn-success"   onclick="$('#dialog').dialog('close');">关闭</button>
		 &nbsp;&nbsp;&nbsp;
		<button type="button" class="btn btn-success"  onclick="submitRule();" >修改</button>
		
	</div>
	</form>
</div>


<div id="adddialog" title="系统提示" style="display:none;">
	<div id="addmsg" style="text-align:center;color:red">&nbsp;</div>
	<table class="table table-bordered table-hover m10">
		 <tr>
	        <td class="tableleft">VIP等级名称</td>
	        <td><input type="text" name="vip_name" id="add_vip_name" /></td>
	   	</tr>
	   	<tr>
	        <td class="tableleft"> 积分下限</td>
	        <td> <input type="text" name="minscore" id="add_minscore" /> </td>
	   	</tr>
	   	<tr>
	        <td class="tableleft"> 积分上限</td>
	        <td><input type="text" name="maxscore" id="add_maxscore" /> </td>
	   	</tr>
	   	<tr>
	        <td class="tableleft"> 购买配比(%)</td>
	        <td><input type="text" name="investpercent" id="add_investpercent" /> </td>
	   	</tr>
	   	<tr>
	        <td class="tableleft">级别图片文件名 </td>
	        <td><input type="text" name="pic" id="add_pic" /> </td>
	   	</tr>
	</table>

	<div style="text-align:center;">
		<button type="button" class="btn btn-success"   onclick="$('#adddialog').dialog('close');">关闭</button>
		 &nbsp;&nbsp;&nbsp;
		<button type="button" class="btn btn-success"  onclick="addsubmitRule();" >修改</button>
	</div>
</div>
<div class="definewidth m20">
		<form  class="form-inline definewidth m20">
  			<button type="button" class="btn btn-success"  onclick="addRule();" >添加投资积分规则</button>
  			如需新增级别图标，请先将图片通过FTP上传到您服务器项目下的 static\credit 目录下
  		</form>
		<table class="table table-bordered table-hover definewidth m10">
			    <tr>
			        <th><strong>VIP等级名称</strong></th>
					<th><strong>积分下限</strong></th>
					<th><strong>积分上限</strong></th>
					<th><strong>购买配比(%)</strong></th>
					<th><strong>级别图片名称</strong></th>
					<th><strong>图片显示</strong></th>
					<th><strong>操作</strong></th>
			    </tr>
			 <?php if($list){foreach ($list as $v){?>
			  	 <tr>
				<td><?php echo $v['vip_name'];?></td>
				<td><?php echo $v['minscore'];?></td>
				<td><?php echo $v['maxscore'];?></td>
				<td><?php echo $v['investpercent'];?></td>
				<td><?php echo $v['pic'];?></td>
				<td><img src="/static/credit/<?php echo $v['pic'];?>"/></td>
				<td>
				<a dataid="<?php echo $v['id'];?>" vip_name="<?php echo $v['vip_name'];?>" minscore="<?php echo $v['minscore'];?>"  maxscore="<?php echo $v['maxscore'];?>" investpercent="<?php echo $v['investpercent'];?>" pic="<?php echo $v['pic'];?>" 
				onclick="changeRule(this);" href="javascript:;">编辑</a>
				&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:removeRule(<?php echo $v['id'];?>);">删除</a></td>
			  </tr>	
			  <?php }}?>
			  	<tr>
			  	<td colspan="8"  class="page"><?php echo $this->pagination->create_links();?></td>
			  	</tr>
		</table>
</div>